<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<meta charset="utf-8">
	<title></title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" type="text/css" th:href="${#request.getContextPath()}+'/static/layui/css/layui.css'" media="all"/>
	<link rel="stylesheet" type="text/css" th:href="${#request.getContextPath()}+'/static/css/thesame.css'" media="all"/>
	<link rel="stylesheet" type="text/css" th:href="${#request.getContextPath()}+'/static/foodDelivery/css/rightCon.css'" media="all"/>
	<link rel="stylesheet" type="text/css" th:href="${#request.getContextPath()}+'/static/foodDelivery/css/popCss.css'" media="all"/>
	<link rel="stylesheet" type="text/css" th:href="${#request.getContextPath()}+'/static/foodDelivery/css/page.css'" media="all"/>
	<link rel="stylesheet" type="text/css" th:href="${#request.getContextPath()}+'/static/foodDelivery/css/tree.css'" media="all"/>
	<style>
		.money-time .layui-laydate, .money-time .layui-laydate-hint {

			border-radius: 4px;
			box-shadow: none;
			border: 1px solid #ddd;
			display: block;
		}
		.money-time .layui-laydate-list{ border-radius: 4px; }
		.money-time .layui-laydate-footer{ height: 62px !important; text-align: center; padding: 15px 0; }
		.money-time .laydate-footer-btns{ position: unset;; }
		.money-time .laydate-footer-btns span{ width: 60px; margin: 0 20px; height: 32px; line-height: 32px; border-radius: 4px; }
		.money-time .laydate-footer-btns span:nth-child(1){ color: #666; }
		.money-time .laydate-footer-btns span:last-child{ border: 1px solid #1C9399; color: #1C9399; }

		.money-time .layui-laydate .layui-this {
			background-color: #1C9399!important;
			color: #fff!important;
		}

		.layui-tab-child-one .layui-tab-title{ display: inline-block; overflow: hidden; height: 38px; border-radius: 4px; }
		.layui-tab-child-one .layui-tab-title,.layui-tab-child-one .layui-tab-title .layui-this:after{ border:0; }
		.layui-tab-child-one .layui-tab-title li{
			float: left;
			width: 160px;
			padding: 0;
			border-radius: 4px 0 0 4px;
			margin-right: 0;
			height: 36px;
			line-height: 36px;
			background-color: #fff;
			border: 1px solid #ddd;
		}
		.layui-tab-child-one .layui-tab-title li:nth-child(1){ border-radius: 4px 0 0 4px; }
		.layui-tab-child-one .layui-tab-title li:nth-child(2){ border-radius: 0 4px 4px 0; }
		.layui-tab-child-one .layui-tab-title .layui-this {
			color: #fff;
			background-color: #1C9399;
			border: 1px solid #1C9399;
		}
		.layui-tab-child-one .layui-tab-title .layui-this {
			color: #fff;
		}
	</style>
</head>

<body class="layui-layout-body">
<div style="display: none">
	<div id="shiroPermission1"><shiro:hasPermission name="dingdanguanli_cud"><span class="goToDetails" lay-event="goToDetails">详情</span></shiro:hasPermission></div>
	<div id="shiroPermission2"><shiro:hasPermission name="dingdanshiguanli_sbpq"><span class="reportingButton" lay-event="reportingButton">上报片区</span></shiro:hasPermission><shiro:hasPermission name="dingdanguanli_sndfd"><span class="deliverButton" lay-event="deliverButton">交付配餐</span></shiro:hasPermission><shiro:hasPermission name="dingdanguanli_cud"><span class="goToDetails" lay-event="goToDetails">详情</span><span class="deleteButton" lay-event="deleteButton">删除</span></shiro:hasPermission></div>
	<div id="shiroPermission3"><shiro:hasPermission name="dingdanguanli_cud"><span class="goToDetails" lay-event="goToDetails">详情</span></shiro:hasPermission><shiro:hasPermission name="dingdanshiguanli_exp"><span class="exportButton" lay-event="exportButton">导出</span></shiro:hasPermission></div>
	<!--<div id="shiroPermission1"><span class="goToDetails" lay-event="goToDetails">详情</span></div>
	<div id="shiroPermission2"><span class="reportingButton" lay-event="reportingButton">上报片区</span><span class="deliverButton" lay-event="deliverButton">交付配餐</span><span class="goToDetails" lay-event="goToDetails">详情</span><span class="deleteButton" lay-event="deleteButton">删除</span></div>
	<div id="shiroPermission3"><span class="goToDetails" lay-event="goToDetails">详情</span><span class="exportButton" lay-event="exportButton">导出</span></div>-->
</div>
<div class="layui-body">
	<!-- 内容主体区域 -->
	<div class="scroll-box bgWhite box-shadows1 border-radius4">
		<div class="new-add-box-scroll">
			<div class="layui-tab" lay-filter="tab_switch">
				<ul class="layui-tab-title pl15px" id="monthTypeUl">
					<li class="layui-this" data-type="1">本月订餐</li>
					<li data-type="2">下月订餐</li>
					<li data-type="3">往月订餐</li>
				</ul>
				<div class="layui-tab-content bgWhite" style="padding: 25px;">
					<div class="layui-tab-item layui-show">
						<div class="border-bot1px pb20px mb20px">
							<div class="add-mess add-mess-con add-mess-con-width">
								<div class="add-mess-child mr40px">
									<div>
										<label>关键字：</label>
									</div>
									<div class="add-mess-form">
										<p>
											<input id="nameSearch_1" type="text" placeholder="请输入订单名称">
										</p>
									</div>
								</div>
								<div class="add-mess-child">
									<div>
										<label>村居范围：</label>
									</div>
									<div class="add-mess-form">
										<p class="add-mess-form-tree"><input id="orgSearch_1" type="hidden"><input readonly style="cursor: pointer"  id="orgNameSearch_1"  type="text" placeholder="请选择" class="form-input"></p>
										<div class="tree-con-box" hidden="hidden" id="org_div_1">

										</div>
									</div>
								</div>
								<div class="overflow">
									<span class="white border-radius4 bgGreen left pl20px pr20px ml30px lh34px cursor" id="searchButton_1">查&nbsp;询</span>
									<span class="border-radius4 border1px-ddd left pl20px pr20px ml30px lh32px cursor" id="resetButton_1">重&nbsp;置</span>
								</div>
							</div>
							<div style="clear: both"></div>
						</div>
						<div class="lh32px overflow add-btn-input mb20px">
							<p class="right">
								<span>共有<em class="red fb ml5px mr5px pageCount_1">0</em>条数据</span>
							</p>
						</div>

						<div class="border1px border-radius4 relative table-time">
							<table class="layui-hide" id="table_1" lay-filter="table_1"></table>
						</div>

					</div>
					<div class="layui-tab-item">
						<div class="border-bot1px pb20px mb20px">
							<div class="add-mess add-mess-con">
								<div class="add-mess-child mr40px">
									<div>
										<label>关键字：</label>
									</div>
									<div class="add-mess-form">
										<p>
											<input id="nameSearch_2" type="text" placeholder="请输入订单名称">
										</p>
									</div>
								</div>
								<div class="add-mess-child mr40px">
									<div>
										<label>村居范围：</label>
									</div>
									<div class="add-mess-form">
										<p class="add-mess-form-tree"><input type="hidden" id="orgSearch_2"><input type="text" readonly id="orgNameSearch_2" style="cursor: pointer" placeholder="请选择" class="form-input"></p>
										<div class="tree-con-box" hidden="hidden" id="org_div_2">

										</div>
									</div>
								</div>
								<div class="add-mess-child mr40px">
									<div>
										<label>订单状态：</label>
									</div>
									<div class="add-mess-form">
										<p>
											<select id="statusSearch_2" class="form-input">
												<option value ="">请选择</option>
												<option value ="1">未报片区</option>
												<option value ="2">已报片区</option>
												<option value ="3">已交配餐</option>
											</select>
										</p>
									</div>
								</div>
								<div class="overflow">
									<span class="white border-radius4 bgGreen left pl20px pr20px ml30px lh34px cursor" id="searchButton_2">查&nbsp;询</span>
									<span class="border-radius4 border1px-ddd left pl20px pr20px ml30px lh32px cursor" id="resetButton_2">重&nbsp;置</span>
								</div>
							</div>
							<div style="clear: both"></div>
						</div>
						<div class="mb20px lh32px overflow add-btn-input">
							<p class="left cursor">
								<shiro:hasPermission name="dingdanguanli_cud"><span th:data-month="${nextMonth}" class="white border-radius4 bgGreen inline-block pl15px pr15px mr20px" id="nextMonth_addOrder"><img th:src="${#request.getContextPath()}+'/static/img/button_add.png'">新增订单</span></shiro:hasPermission>
								<shiro:hasPermission name="dingdanguanli_sndfd"><span class="white border-radius4 bgGreen inline-block pl15px pr15px" id="nextMonth_batchDeliver"><img th:src="${#request.getContextPath()}+'/static/img/button_add.png'">批量交付配餐</span></shiro:hasPermission>
							</p>
							<p class="right"><span>共有<em class="red fb ml5px mr5px pageCount_2">0</em>条数据</span></p>
						</div>
						<div class="border1px border-radius4 relative mb40px">
							<table class="layui-hide" id="table_2" lay-filter="table_2"></table>
						</div>
					</div>
					<div class="layui-tab-item">
						<div class="border-bot1px pb20px mb20px">
							<div class="add-mess add-mess-con add-mess-con-width">
								<div class="add-mess-child mr40px">
									<div>
										<label>关键字：</label>
									</div>
									<div class="add-mess-form">
										<p>
											<input type="text" id="nameSearch_3" placeholder="请输入订单名称">
										</p>
									</div>
								</div>
								<div class="add-mess-child">
									<div>
										<label>村居范围：</label>
									</div>
									<div class="add-mess-form">
										<p class="add-mess-form-tree"><input type="hidden" id="orgSearch_3"><input id="orgNameSearch_3" type="text" readonly style="cursor: pointer" placeholder="请选择" class="form-input"></p>
										<div class="tree-con-box" hidden="hidden" id="org_div_3">

										</div>
									</div>
								</div>
								<div class="overflow">
									<span class="white border-radius4 bgGreen left pl20px pr20px ml30px lh34px cursor" id="searchButton_3">查&nbsp;询</span>
									<span class="border-radius4 border1px-ddd left pl20px pr20px ml30px lh32px cursor" id="resetButton_3">重&nbsp;置</span>
								</div>
							</div>
							<div style="clear: both"></div>
						</div>
						<div class="mb20px lh32px overflow add-btn-input">
							<p class="left cursor">
								<shiro:hasPermission name="dingdanguanli_batch_export"><span class="white border-radius4 bgGreen inline-block pl15px pr15px mr20px" id="exportMonthData"><img th:src="${#request.getContextPath()}+'/static/img/icon_daochu.png'" style="vertical-align: -1px;">导出月度明细</span></shiro:hasPermission>
							</p>
							<p class="right"><span>共有<em class="red fb ml5px mr5px pageCount_3">0</em>条数据</span></p>
						</div>

						<div class="border1px border-radius4 relative table-time">
							<table class="layui-hide" id="table_3" lay-filter="table_3"></table>
						</div>

					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script th:src="${#request.getContextPath()}+'/static/js/jquery-2.1.3.min.js'"></script>
<script th:src="${#request.getContextPath()}+'/static/layui/layui.js'"></script>
<script>
	var basePath = $("input#basePathInput",parent.document).val();
	var table1_init = false;
	var table2_init = false;
	var table3_init = false;
	var pageType = "1";
	var batchSave = true;
	var orgData;
	var tableData = [{
		"username": "小茗同学",
		"sex": 1,
		"city": "用户管理",
		"sign": "open:user:manage",
		"experience": "100",
		"score": "111",
		"classify": "222",
		"operation": "详情"
	}, ];
	//左侧菜单栏
	layui.use(['element','table', 'layer',"laydate"], function() {
		var element = layui.element;
		var table = layui.table;
		var layer = layui.layer;
		var $ = layui.jquery;
		var laydate = layui.laydate;
		var basics_cols = [{
			field: 'id',
			title: '编号',
			hide: true
		}, {
			field: 'org_id',
			title: '地区',
			hide: true
		},{
			type: 'numbers',
			title: '序号',
			fixed: 'left',
			width:80
		}, {
			field: 'month',
			title: '订单月份',
			templet: function(d){
				var val = d.month;
				if(val && $.trim(val) && "null" != val){
					return val.substring(0,4)+"-"+val.substring(4,6);
				}else{
					return "";
				}

			}
		}, {
			field: 'name',
			title: '订单名称',
		}, {
			field: 'create_time',
			title: '创建时间',
		}, {
			field: 'update_time',
			title: '更新时间',
		}, {
			field: 'status',
			title: '订单状态',
			templet: function(d){
				var val = d.status;
				if(val && $.trim(val) && "null" != val){
					if(val == "1" || val == 1){
						return "未报片区"
					}else if(val == "2" || val == 2){
						return "已报片区"
					}else if(val == "3" || val == 3){
						return "已交配餐";
					}else{
						return "";
					}
				}else{
					return "";
				}
			}
		}
		];

		$.ajax({
			url:"../org/getAllAuthTypeOrg",
			type:"post",
			dataType:"json",
			data:{"type":"3","userFlag":"yes"},
			success:function (result) {
				if(result.children && result.children.length > 0){
					let str = "";
					$.each(result.children,function(index,ao){
						str+='<div id="select_user_root_node" style="cursor: pointer" data-orgid="'+ao.orgId+'" data-orgname="'+ao.orgName+'" class="border-bot1px pl20px pr20px lh45px gray"><span class="mr10px">'+ao.orgName+'</span><span>无上级组织</span></div>';
						if(ao.isChildExist=='1' && ao.children && ao.children.length>0){
							str+='<ul class="tree-one">';
							$.each(ao.children,function(index,ao1){
								str+='<li>';
								str+='<div class="tree-children">';
								str+='<div>';
								if(ao1.isChildExist=='1'){
									str+='<p class="tree-arrow cursor"><img src="'+basePath+'/static/org/img/icon_select_down.png"></p>';
									str+='<p data-orgid="'+ao1.orgId+'">'+ao1.orgName+'</p>';
								}else{
									str+='<p style="margin-left:17px" data-orgid="'+ao1.orgId+'">'+ao1.orgName+'</p>';
								}
								str+='</div>';
								str+='</div>';
								if(ao1.isChildExist=='1' && ao.children!=null && ao.children.length>0){
									str+='<ul class="tree-two">';
									$.each(ao1.children,function(index,ao2){
										str+='<li>';
										str+='<div class="tree-children">';
										str+='<div>';
										if(ao2.isChildExist=='1'){
											str+='<p class="tree-arrow cursor"><img src="'+basePath+'/static/org/img/icon_select_down.png"></p>';
											str+='<p data-orgid="'+ao2.orgId+'">'+ao2.orgName+'</p>';
										}else{
											str+='<p style="margin-left:8px" data-orgid="'+ao2.orgId+'">'+ao2.orgName+'</p>';
										}
										str+='</div>'
										str+='</div>';
										if(ao2.isChildExist=='1' && ao2.children!=null && ao2.children.length>0){
											str+='<ul class="tree-three">';
											$.each(ao2.children,function(index,ao3){
												str+='<li>';
												str+='<div class="tree-children">';
												str+='<div>';
												if(ao3.isChildExist=='1'){
													str+='<p class="tree-arrow cursor"><img src="'+basePath+'/static/org/img/icon_select_down.png"></p>';
													str+='<p data-orgid="'+ao3.orgId+'">'+ao3.orgName+'</p>';
												}else{
													str+='<p style="margin-left:8px" data-orgid="'+ao3.orgId+'">'+ao3.orgName+'</p>';
												}
												str+='</div>'
												str+='</div>';
												if(ao3.isChildExist=='1' && ao3.children!=null && ao3.children.length>0){
													str+='<ul class="tree-four">';
													$.each(ao3.children,function(index,ao4){
														str+='<li>';
														str+='<div class="tree-children">';
														str+='<div>';
														if(ao4.isChildExist=='1'){
															str+='<p class="tree-arrow cursor"><img src="'+basePath+'/static/org/img/icon_select_down.png"></p>';
															str+='<p data-orgid="'+ao4.orgId+'">'+ao4.orgName+'</p>';
														}else{
															str+='<p style="margin-left:8px" data-orgid="'+ao4.orgId+'">'+ao4.orgName+'</p>';
														}
														str+='</div>'
														str+='</div>';
														if(ao4.isChildExist=='1' && ao4.children!=null && ao4.children.length>0){
															str+='<ul class="tree-four">';
															$.each(ao4.children,function(index,ao5){
																str+='<li>';
																str+='<div class="tree-children">';
																str+='<div>';
																str+='<p style="margin-left:8px" data-orgid="'+ao5.orgId+'">'+ao5.orgName+'</p>';
																str+='</div>'
																str+='</div>';
																str+='</li>';
															})
															str+='</ul>'
														}
														str+='</li>';
													})
													str+='</ul>'
												}
												str+='</li>';
											})
											str+='</ul>';
										}
										str+='</li>';
									})
									str+='</ul>';
								}
								str+='</li>';
							});
							str+='</ul>';
						}
						str+='';
					});
					$("div[id*='org_div_']").each(function (i,v) {
						let that = this;
						$(that).html(str);

						$(that).prev().find('.add-mess-form-tree').on("click",function () {
							$(this).next().slideToggle();
						})

						$('.tree-one div.tree-children div p.tree-arrow',$(that)).on("click",function () {
							$(this).parent().parent('div.tree-children').next('ul').slideToggle(300);
							if ($(this).find('img').attr('src').indexOf('/static/img/icon_select_up.png') != -1) {
								$(this).find('img').attr('src', basePath+'/static/img/icon_select_down.png');
							} else {
								$(this).find('img').attr('src', basePath+'/static/img/icon_select_up.png');
							}
						})

						$('.tree-one div.tree-children div p:not(".tree-arrow")',$(that)).on("click",function () {
							var orgNo = $(this).data("orgid")
							$("input#selectUser_org_search").val(orgNo);
							$('.add-mess-form-tree').trigger("click");
							$("input#orgSearch_"+pageType).val(orgNo);
							$("input#orgNameSearch_"+pageType).val($(this).text());
						})

						$('div#select_user_root_node').on("click",function () {
							$('.add-mess-form-tree').trigger("click");
							$("input#orgNameSearch_"+pageType).val($(this).data('orgname'));
							$("input#orgSearch_"+pageType).val($(this).data("orgid"));
						})
					})
				}else{
					layer.msg("未获取到组织机构数据！");
				}
			}
		})

		var cols = basics_cols.slice();
		cols.push( {
			field: 'operation',
			title: '操作',
			style: 'color:#1C9399',
			fixed: 'right',
			templet: function(res){
				return "<div class='table-list-btn'>"+$("div#shiroPermission"+pageType).html()+"</div>"
			}
		})

		$('.tree-one div.tree-children div').click(function() {
			$('.tree-one div.tree-children div').removeClass("current");
			$(this).addClass('current');
			$(this).parent('div.tree-children').nextAll('ul').slideToggle(300);
			if ($(this).find('img').attr('src') == 'img/icon_select_up.png') {
				$(this).find('img').attr('src', 'img/icon_select_down.png');
				//$(this).parent().siblings().find('img').attr('src', 'img/icon_select_up.png')
				$('.tree-one div.tree-children div').removeClass("current");
			} else {
				$(this).find('img').attr('src', 'img/icon_select_up.png');
			}
		})
		$('.add-mess-form-tree').click(function(){
			$(this).next().slideToggle();
		})

		initTable($,table,"table_"+pageType,"",cols);

		element.on('tab(tab_switch)', function(){
			$("div[id*='org_div_']").hide();
			let type = $(this).data("type");
			if(parseInt(type) != parseInt(pageType)) {
				pageType = type;
				cols = basics_cols.slice();
				cols.push( {
					field: 'operation',
					title: '操作',
					style: 'color:#1C9399',
					fixed: 'right',
					templet: function(res){
						return "<div class='table-list-btn'>"+$("div#shiroPermission"+pageType).html()+"</div>"
					}
				})
				initTable($,table,"table_" + pageType, "", cols);
			}
		});

		$("span#exportMonthData").on("click",function (e) {
			//window.location.href="../orderingRecords/exportExcel?id=49";
			layer.open({
				type: 1,
				title: false, //不显示标题栏
				closeBtn: false,
				area: ['330px', '450px'],
				shade: 0.6,
				id: 'payCons', //设定一个id，防止重复弹出
				/*,btn: ['确认支付']*/
				btnAlign: 'c',
				moveType: 1, //拖拽模式，0或者1
				shadeClose: true, //设置允许点遮罩关闭
				content: '<div style="padding: 15px 30px;"><div class="money-time"><div class="pop-title relative overflow mb15px"><span class="ml15px">助餐点考勤明细报表导出</span><p class="right pop-close"><img src="../static/img/close_icon.png" class="block pop-close"><p></div><div class="mt30px mb30px textCenter"><div class="layui-inline" id="test-month"></div></div></div></div>',
				success: function() {
					laydate.render({
						elem: '#test-month',
						type: 'month',
						position: 'static',
						btns: ['clear', 'confirm'],
						done:function (value) {
							if(value) {
								layer.closeAll();
								window.location.href = "../orderingRecords/exportExcel?month=" + value.replace("-", "");
							}else{
								layer.msg("请先选择月份！");
							}
						}
					});
					//关闭弹层
					$(".pop-close").click(function() {
						layer.closeAll();
					});
				},

			});
		})

		$("span#nextMonth_addOrder").on("click",function (e) {
			let nextMonth = $(this).data("month")+"";
			let nextMonthStr = nextMonth.substring(0,4)+"年"+nextMonth.substring(4,6)+"月";
			let html = '';
			let index = layer.open({
				type: 1,
				title: false, //不显示标题栏
				closeBtn: false,
				area: ['500px', ''],
				shade: 0.6,
				id: 'payCons', //设定一个id，防止重复弹出
				btnAlign: 'c',
				moveType: 1, //拖拽模式，0或者1
				shadeClose: true, //设置允许点遮罩关闭
				content: getNextMonthLayerHtml(nextMonthStr,layer),
				success: function() {
					//关闭弹层  newNextMonthNext 下一步  newOrderNameDiv 订餐名称   newOrderOrgSelect
					$(".layer_pop-close").on("click",function() {
						layer.close(index);
					});

					$("select#newOrderOrgSelect").on("change",function (e) {
						let val = $(this).val();
						if(val){
							$("div#newOrderNameDiv").text($(this).find("option:selected").text()+"-"+nextMonth);
						}else{
							$("div#newOrderNameDiv").text("");
						}
					})

					$("span#newNextMonthNext").on("click",function (e) {
						let orgId = $("select#newOrderOrgSelect").val();
						if(orgId){
							let orgName = $("select#newOrderOrgSelect").find("option:selected").text();
							$.ajax({
								url:"../ordering/hasMonthOrder",
								type:"post",
								dataType:"json",
								data:{"month": nextMonth,"orgId":orgId},
								success:function (result) {
									if(result.code == 200){
										if(result.data == "yes"){
											let name = orgName+"-"+nextMonth;
											window.location.href="../orderingRecords/addNextMonth?month="+nextMonth+"&name="+name+"&orgId="+orgId+"&orgName="+orgName+"&type="+pageType;
										}else{
											layer.msg(orgName + nextMonthStr+"订单已存在！");
										}
									}else{
										layer.msg("系统错误！");
									}
								}
							})
						}else{
							layer.msg("请选择村居！");
						}
					})
				},
			});
		})

		$("span#nextMonth_batchDeliver").on("click",function (e) {
			if(batchSave) {
				basePath = false;
				let state = "";
				if ($("select#statusSearch_" + pageType) && $("select#statusSearch_" + pageType).length > 0) {
					state = $("select#statusSearch_" + pageType).val();
				}
				$.ajax({
					url: "../ordering/batchDeliver",
					type: "post",
					dataType: "json",
					data: {
						"type": pageType,
						"name": $("input#nameSearch_" + pageType).val(),
						"orgId": $("input#orgSearch_" + pageType).val(),
						"state": state
					},
					success: function (result) {
						setTimeout(function () {
							basePath = true;
						},3000)
						layer.msg(result.msg);
						if (result.code == 200) {
							table.reload("table_" + pageType, {
								where: {
									"type": pageType,
									"name": $("input#nameSearch_" + pageType).val(),
									"orgId": $("input#orgSearch_" + pageType).val(),
									"state": state
								},
							});
						}
					}
				})
			}
		})
	});

	function initTable($,table,tableId,url,cols) {
		var flag = true;
		if(pageType == "1" || pageType == 1){
			if(table1_init){
				flag = false;
			}else{
				table1_init = true;
			}
		}else if(pageType == "2" || pageType == 2){
			if(table2_init){
				flag = false;
			}else{
				table2_init = true;
			}
		}else if(pageType == "3" || pageType == 3){
			if(table3_init){
				flag = false;
			}else{
				table3_init = true;
			}
		}
		if(flag) {
			table.render({
				elem: "#" + tableId,
				url: "../ordering/getData",
				id: tableId,
				method: "post",
				request: {
					pageName: 'page',
					limitName: 'pageSize'
				},
				where: {"type": pageType},
				page: true, //开启分页
				cols: [cols],
				done: function (res, curr, count) {
					$("em.pageCount_" + pageType).text(count);
					/*if(res.status == "2" || res.status == 2){
						$("span.reportingButton").remove();
					}*/
					let tableView = this.elem.next();
					layui.each(res.data, function(i, item) {
						if (parseInt(item.status) != 1 ) {
							tableView.find('tr[data-index=' + i + ']').find('span.reportingButton').remove();
						}
						if (parseInt(item.status) != 2 ) {
							tableView.find('tr[data-index=' + i + ']').find('span.deliverButton').remove();
						}
					})

					$("span#searchButton_"+pageType).unbind().on("click",function (e) {
						let state = "";
						if($("select#statusSearch_"+pageType) && $("select#statusSearch_"+pageType).length > 0){
							state = $("select#statusSearch_"+pageType).val();
						}
						table.reload(tableId, {
							where: {"type": pageType,"name":$("input#nameSearch_"+pageType).val(),"orgId":$("input#orgSearch_"+pageType).val(),"state":state},
						});
					})
					$("span#resetButton_"+pageType).unbind().on("click",function (e) {
						$("input#nameSearch_"+pageType).val("");
						$("input#orgSearch_"+pageType).val("");
						$("input#orgNameSearch_"+pageType).val("");
						$("select#statusSearch_"+pageType).val("");
						table.reload(tableId, {
							where: {"type": pageType,"name":"","orgId":"","state":""},
						});
					})
				}
			});

			table.on('tool('+tableId+')', function(obj){
				let data = obj.data;
				switch(obj.event){
					case 'goToDetails':
						let name = data.name;
						let orgName = name.split("-")[0];
						window.location.href = "../orderingRecords/addNextMonth?month="+data.month+"&name="+name+"&orgId="+data.org_id+"&orgName="+orgName+"&orderId="+data.id+"&type="+pageType;
						break;
					case 'reportingButton':
						$.ajax({
							url:"../ordering/reporting",
							type:"post",
							dataType:"json",
							data:{"id":data.id},
							success:function (result) {
								layer.msg(result.msg);
								if(result.code == 200){
									let state = "";
									if($("select#statusSearch_"+pageType) && $("select#statusSearch_"+pageType).length > 0){
										state = $("select#statusSearch_"+pageType).val();
									}
									table.reload(tableId, {
										where: {"type": pageType,"name":$("input#nameSearch_"+pageType).val(),"orgId":$("input#orgSearch_"+pageType).val(),"state":state},
									});
								}
							}
						})
						break;
					case 'deliverButton':
						$.ajax({
							url:"../ordering/deliver",
							type:"post",
							dataType:"json",
							data:{"id":data.id},
							success:function (result) {
								layer.msg(result.msg);
								if(result.code == 200){
									let state = "";
									if($("select#statusSearch_"+pageType) && $("select#statusSearch_"+pageType).length > 0){
										state = $("select#statusSearch_"+pageType).val();
									}
									table.reload(tableId, {
										where: {"type": pageType,"name":$("input#nameSearch_"+pageType).val(),"orgId":$("input#orgSearch_"+pageType).val(),"state":state},
									});
								}
							}
						})
						break;
					case 'deleteButton':
						layer.confirm('确认删除该条数据吗？', function(index){
							layer.close(index);
							$.ajax({
								url:"../ordering/delete",
								type:"post",
								dataType:"json",
								data:{"id":data.id},
								success:function (result) {
									layer.msg(result.msg);
									if(result.code == 200){
										let state = "";
										if($("select#statusSearch_"+pageType) && $("select#statusSearch_"+pageType).length > 0){
											state = $("select#statusSearch_"+pageType).val();
										}
										table.reload(tableId, {
											where: {"type": pageType,"name":$("input#nameSearch_"+pageType).val(),"orgId":$("input#orgSearch_"+pageType).val(),"state":state},
										});
									}
								}
							})
						});
						break;
					case 'exportButton':
						window.location.href="../orderingRecords/exportExcel?id="+data.id;
						break;
				};
			});
		}
	}

	function getNextMonthLayerHtml(monthStr,layer) {
		let html = '<div id="pop-con"><div class="pop-up"><div><div class="pop-title relative overflow mb15px"><span class="ml15px">创建月度订单</span><p class="right layer_pop-close" style="cursor: pointer"><img src="'+basePath+'/static/img/close_icon.png" class="block pop-close"><p></div><div class="pop-form pop-form-right mt30px mb30px"><div class="lh32px"><div class="layui-form-item"><label class="layui-form-label">订餐年月：</label><div class="layui-input-block">'+monthStr+'</div></div><div class="layui-form-item"><label class="layui-form-label"><span class="red">*</span>村居：</label><div class="layui-input-block border-radius4 border1px pl15px pr15px border-box"><select id="newOrderOrgSelect" class="form-select">';
		html+= '<option value ="">请选择</option>';
		if(!(orgData && orgData.length > 0)){
			$.ajax({
				url:"../ordering/getUserOrg",
				type:"post",
				dataType:"json",
				async:false,
				success:function (result) {
					if(result.code == 200){
						orgData = result.data;
					}else{
						layer.msg(result.msg);
					}
				}
			})
		}
		if(orgData && orgData.length > 0){
			orgData.forEach(function (v,i) {
				html+= '<option value="'+v.org_id+'">'+v.org_name+'</option>';
			})
		}
		html += '</select></div></div><div class="layui-form-item"><label class="layui-form-label">订餐名称：</label><div class="layui-input-block" id="newOrderNameDiv"></div></div></div></div><div class="btn-con textCenter"><span class="btn-one layer_pop-close"  style="cursor: pointer">取&nbsp;消</span><span class="btn-two" id="newNextMonthNext"  style="cursor: pointer">下一步</span></div></div></div></div>';
		return html;
	}
</script>
</body>

</html>
